package net.tv90.appserveradmin.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.thymeleaf.dialect.SaTokenDialect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenConfig implements WebMvcConfigurer {

    // Sa-Token 标签方言 (Thymeleaf版)
    @Bean
    public SaTokenDialect getSaTokenDialect() {
        return new SaTokenDialect();
    }

//    // 为 Thymeleaf 注入全局变量，以便在页面中调用 Sa-Token 的方法
//    @Autowired
//    private void configureThymeleafStaticVars(ThymeleafViewResolver viewResolver) {
//        viewResolver.addStaticVariable("stp", StpUtil.stpLogic);
//    }

    // 注册 Sa-Token 拦截器，打开注解式鉴权功能
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，打开注解式鉴权功能
        registry.addInterceptor(new SaInterceptor()).addPathPatterns("/**");
    }

}
